using System;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using BookBarter;

/// <summary>
/// This class is the base for any notification.  Its children are used for specific notifications such as RSS or Email
/// </summary>
public abstract class Notifier
{
    private Person _person;
    private string _title;
    private string _message;
    private string _link;

    //user information
    public Person GetPerson
    {
        get { return _person; }
    }

    //book information
    public string GetTitle //"new trade" or "trade cancelled"
    {
        get { return _title; }
    }

    //messaging information
    public string GetMessage //message constructed from the link
    {
        get { return _message; }
    }

    public string GetLink //web link to confirmation page
    {
        get { return _link; }
    }

	public Notifier()
	{
		//
		// TODO: Add constructor logic here
		//

	}

    /// <summary>
    /// construct the messages to be sent out
    /// </summary>
    /// <param name="linkNode"></param>
    /// <param name="isCancelled"></param>
    internal void ConstructMessage(TradeLink tradeLink, AcceptedStatus accepted)
    {
        //A message should be constructed here for each of the subclasses (RSS, Email)


        _person = tradeLink.Want.Person;
        _link = "http://localhost:1027/BookTrader_01/TradeManagement.aspx?TradeChainLink=" + tradeLink.ID;

        StringBuilder message = new StringBuilder();
        message.Append("Dear ").Append(_person.FirstName);
        message.Append(" The trade between ").Append(tradeLink.Have.Person.UserId).Append("'s book, ").Append(tradeLink.Want.Book.Title);
        message.Append(", for your book, ").Append(tradeLink.Have.Book.Title).Append(" has been ");

        switch (accepted)
        {
            case AcceptedStatus.Pending: //new trade
                message.Append("Established.");
                _title = "New Trade!";
                break;

            case AcceptedStatus.Cancelled: //cancelled trade
                message.Append("Cancelled.");
                _title = "Trade Cancelled!";
                break;
        }
        message.Append("       "+_link);

        //message.Append("  Please follow the link for more information.");
        _message = message.ToString();
    }

    internal void ConstructMessage()
    {
        //this takes no paremeters so we can test without a TradeChainLink or isCancled
        _message = "this is your example message with your book (A) that you will trade with user x to get book (B)";
    }
}
